<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>SwiftLaTeX: WYSIWYG LaTeX Editor for Browsers</title>
</head>
<body>
<script>
    let hashString = window.location.hash;
    if (hashString.startsWith('#')) {
        hashString = hashString.slice(1);
    }
    const urlParams = new URLSearchParams(hashString);
    const accessToken = urlParams.get('access_token');
    const state = urlParams.get('state');
    let provider = '';
    if (state.startsWith('dropbox')) {
        provider = 'dropbox';
    } else if (state.startsWith('google')) {
        provider = 'google';
    } else if (state.startsWith('github')) {
        provider = 'github';
    }
    if (window.localStorage.getItem('oauthState') === state && provider && accessToken) {
        localStorage.setItem('access_token', accessToken);
        localStorage.setItem('provider', provider);
        window.opener && window.opener.postMessage({ 'authResult': 'ok' }, '*');
        window.top && window.top.postMessage({ 'authResult': 'ok' }, '*');
    } else {
        window.opener && window.opener.postMessage({ 'authResult': 'failed' }, '*');
        window.top && window.top.postMessage({ 'authResult': 'failed' }, '*');
    }
    window.close();
</script>
<script src="meow.js"></script>
</body>
</html>